using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Plugin.Sns.Scene;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Windows.Media.Imaging;
namespace MicroMsg.Plugin.Circle
{
	public class Circle : PluginBase
	{
		private const string TAG = "Circle";
		public const string PluginKey = "plugin Circle";
		public const long PluginID = 32777L;
		public const string PluginName = "Circle";
		public const int PluginVersion = 256;
		public const string cStrHasRequestSnsGroupKey = "HasRequestSnsGroupKey";
		private const string cStrKeyLastObjID = "cStrKeyLastObjID";
		private const string cBLastObjNew = "cBLastObjNew";
		private static Circle mInstance;
		private EventWatcher mWatchUnread;
		private object objWatch = new object();
		public override string mTitle
		{
			get
			{
				return strings.Album__Plugin_Name;
			}
		}
		public override BitmapSource mIcon
		{
			get
			{
				if (MMTheme.IsCoolBlackTheme())
				{
					return ImageCacheMgr.loadFromRes("Source/Plugin/Sns/Common/Resource/pluginicon_cool.png");
				}
				return ImageCacheMgr.loadFromRes("Source/Plugin/Sns/Common/Resource/pluginicon_normal.png");
			}
		}
		public override string mFFEntryTitle
		{
			get
			{
				return strings.Album_FF_Entry;
			}
		}
		public override BitmapSource mIconHD
		{
			get
			{
				return ImageCacheMgr.loadFromRes("Source/Plugin/Sns/Common/Resource/pluginicon_HD.png");
			}
		}
		public override BitmapSource mIconInList
		{
			get
			{
				return this.mIcon;
			}
		}
		public override string mDescription
		{
			get
			{
				return strings.Album_Intro;
			}
		}
		public override string mAuthor
		{
			get
			{
				return "tencent";
			}
		}
		public Circle()
		{
			this.mKey = "plugin Circle";
			this.mID = 32777L;
			this.mName = "Circle";
			this.mVersion = 256;
			this.mIndexInTab = MainTabIndex.FindFriendTab;
			this.mIndexInGroup = 0;
			this.mIndexInPosition = 2;
			this.mProtocolPluginFlag = EPluginFlag.MM_FEEDSAPP_UNINSTALL;
			this.mDefaultInstalled = true;
			Circle.mInstance = this;
			base.mIconInFFEntry = new BitmapImage(new Uri(MMTheme.GetInstance().Sns_ImgPath_ffentryicon, 2));
		}
		public override PluginSettingBaseCtrl GetPluginSettingCtrl()
		{
			return new CirclePluginSetCtrl();
		}
		public static Circle getInstance()
		{
			return Circle.mInstance;
		}
		public override void onRegisterResult(RetConst retConst_0, int code)
		{
			Log.smethod_4("Circle", string.Concat(new object[]
			{
				"on register result , ret = ",
				retConst_0,
				", code = ",
				code
			}));
		}
		public override bool onInitialize()
		{
			Log.smethod_4("Circle", "initialize. ");
			this.registerEvent();
			SnsCommentServiceCenter.init();
			return true;
		}
		public override bool onInstalled(InstallMode mode)
		{
			Log.smethod_4("Circle", "on inistalled. ");
			this.registerEvent();
			this.refreshUnReadCnt();
			return true;
		}
		public override bool onUninstalled(InstallMode mode)
		{
			Log.smethod_4("Circle", "on uninstalled. ");
			base.onUninstalled(mode);
			this.refreshUnReadCnt();
			this.unRegisterEvent();
			return true;
		}
		public override void onAppActivated()
		{
			Log.smethod_4("Circle", "on app activated. ");
		}
		public override void onAppDeactivated()
		{
			Log.smethod_4("Circle", "on app deactiveated. ");
		}
		public override bool onUnInitialize()
		{
			base.onUnInitialize();
			this.unRegisterEvent();
			return true;
		}
		public override object execute(int entryType, object args)
		{
			Log.smethod_4("Circle", "plugin execute,   entrytype =" + entryType);
			Circle.TryGetSnsGroups();
			if (entryType == 1)
			{
				return null;
			}
			if (entryType == 2)
			{
				return null;
			}
			if (entryType == 3)
			{
				object[] pData = new object[]
				{
					default(object),
					"/Source/Plugin/Sns/Circle/UI/CircleMainPage.xaml"
				};
				LocationServiceTipPage.GotoThisPage(pData);
				return null;
			}
			if (entryType == 4)
			{
				object[] pData2 = new object[]
				{
					default(object),
					"/Source/Plugin/Sns/Circle/UI/CircleMainPage.xaml"
				};
				LocationServiceTipPage.GotoThisPage(pData2);
				return null;
			}
			if (entryType == 5)
			{
				object[] array = new object[]
				{
					StorageMgr.contact.method_0(AccountMgr.curUserName)
				};
				object[] pData3 = new object[]
				{
					array,
					"/Source/Plugin/Sns/Album/UI/SnsUserMainPage.xaml"
				};
				LocationServiceTipPage.GotoThisPage(pData3);
			}
			return null;
		}
		public static void TryGetSnsGroups()
		{
			if (!ConfigMgr.getBool("HasRequestSnsGroupKey", false))
			{
				NetSceneSnsTagList.Instance.doScene(SnsTagListOpCode.MM_SNS_TAG_LIST_GET);
			}
		}
		private void registerEvent()
		{
			if (this.mWatchUnread == null)
			{
				this.mWatchUnread = new EventWatcher(this.objWatch, null, new EventHandlerDelegate(this.OnUnReadCntChange));
				EventCenter.registerEventWatcher(EventConst.ON_UNREAD_SNSMSG_CNTCHANGE, this.mWatchUnread);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_SNS_SYNC_NEW_OBJ, this.mWatchUnread);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchUnread != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_UNREAD_SNSMSG_CNTCHANGE, this.mWatchUnread);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_SNS_SYNC_NEW_OBJ, this.mWatchUnread);
				this.mWatchUnread = null;
			}
		}
		private void OnUnReadCntChange(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			EventConst mEventID = evtArgs.mEventID;
			if (mEventID != EventConst.ON_NETSCENE_SNS_SYNC_NEW_OBJ)
			{
				if (mEventID != EventConst.ON_UNREAD_SNSMSG_CNTCHANGE)
				{
					return;
				}
				this.refreshUnReadCnt();
				return;
			}
			else
			{
				SnsInfo snsInfo = evtArgs.mObject as SnsInfo;
				if (snsInfo == null)
				{
					return;
				}
				CircleHubPrevCtrl instance = CircleHubPrevCtrl.getInstance();
				instance.bIsNew = true;
				instance.ItemObject = snsInfo;
				ConfigMgr.setString("cStrKeyLastObjID", snsInfo.strObjectID);
				ConfigMgr.setBool("cBLastObjNew", true);
				if (this.mFFEntryCallBack != null)
				{
					this.mFFEntryCallBack(FFEntryCtrlOpKind.OpKind_SetPrePageContent, instance);
				}
				return;
			}
		}
		private void refreshUnReadCnt()
		{
			int snsMsgUnreadCount = SnsMsgMgr.getSnsMsgUnreadCount();
			this.setUnreadCnt(snsMsgUnreadCount);
		}
		public override void SetFFEntryCallBack(StandardUITaskDlg FFEntryCallBack)
		{
			this.mFFEntryCallBack = FFEntryCallBack;
			this.refreshUnReadCnt();
		}
		private void setUnreadCnt(int nCnt)
		{
			if (this.mFFEntryCallBack != null)
			{
				try
				{
					this.mFFEntryCallBack(FFEntryCtrlOpKind.OpKind_Cnt, nCnt);
				}
				catch
				{
				}
			}
		}
		public void ClearFFEntryInfo()
		{
			if (this.mFFEntryCallBack != null)
			{
				this.mFFEntryCallBack(FFEntryCtrlOpKind.OpKind_SetPrePageContent, null);
			}
			ConfigMgr.setString("cStrKeyLastObjID", "");
			ConfigMgr.setBool("cBLastObjNew", false);
		}
		public void SetFFEntryInfoCallBack(string strId, object ctrl)
		{
			if (this.mFFEntryCallBack != null)
			{
				this.mFFEntryCallBack(FFEntryCtrlOpKind.OpKind_SetPrePageContent, ctrl);
			}
			ConfigMgr.setString("cStrKeyLastObjID", strId);
			ConfigMgr.setBool("cBLastObjNew", false);
		}
		public override void OnShowInFFEntry()
		{
			base.OnShowInFFEntry();
			string @string = ConfigMgr.getString("cStrKeyLastObjID", "");
			CircleHubPrevCtrl instance = CircleHubPrevCtrl.getInstance();
			if (!string.IsNullOrEmpty(@string))
			{
				SnsInfo snsInfo = SnsInfoMgr.smethod_0(SnsInfo.toID(@string));
				if (snsInfo != null)
				{
					instance.bIsNew = ConfigMgr.getBool("cBLastObjNew", false);
					instance.ItemObject = snsInfo;
				}
			}
			if (this.mFFEntryCallBack != null)
			{
				this.mFFEntryCallBack(FFEntryCtrlOpKind.OpKind_SetPrePageContent, instance);
			}
		}
	}
}
